package com.coffee.price;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cauly.android.ad.AdInfo;
import com.cauly.android.ad.AdView;
import com.coffee.price.common.BasicActivity;
import com.coffee.price.common.Const;
import com.coffee.price.common.MoveActivity;

public class BrandListActivity extends BasicActivity {
	
	public RelativeLayout cauly;
	public LinearLayout brand_list;
	
	//private ImageView img;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.brand_list);
        
        //===========타이틀 영역===========
        txt_title = (TextView)findViewById(R.id.txt_title);
        btn_title_right = (ImageButton)findViewById(R.id.btn_title_right);
        btn_title_right.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon_info));
        btn_title_right.setOnClickListener(this);
        //===========타이틀 영역===========
        
        //부모 레이아웃.
        cauly = (RelativeLayout)findViewById(R.id.cauly_layout);
        brand_list = (LinearLayout)findViewById(R.id.brand_list);
        
        //데이터 채우기
        AdInfo info = new AdInfo();
        info.initData("w8LQXZAq0F", "cpc", "all", "all", "off", "circle", "yes", 90);
        
        //광고 View
        AdView adView = new AdView(this);
        
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
				LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);	
        //부모 레이어 하단에 위치할때.
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        
        adView.setVisibility(View.VISIBLE);
		adView.setLayoutParams(params);
		//adView.setAdListener(this);
		
		//레이아웃 적용.
		cauly.addView(adView);
		
		this.BrandForLog();
    }
    
    public void onClick(View v) {
    	
    	if(v == btn_title_right){
    		MoveActivity m = new MoveActivity(BrandListActivity.this , AppsInfoActivity.class);
    		m.go();
    	}
    }
    
    public void goPriceList(int index) {
    	
    	MoveActivity move = new MoveActivity(BrandListActivity.this , PriceListActivity.class);
    	move.putExtra("brand_code", "0"+(index+1));
		move.go();
    }
    
    public View brandAddView(int i){
    	
    	LayoutInflater inflater = getLayoutInflater();
		View v = inflater.inflate(R.layout.brand_row, null);
		ImageView img = (ImageView) v.findViewById(R.id.brand_img);
		img.setId(i);
		img.setImageDrawable(getResources().getDrawable(Const.logo[i]));
		//img.setOnClickListener(this);
		img.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				//Toast.makeText(BrandListActivity.this, "ID : " + v.getId(), Toast.LENGTH_SHORT).show();
				goPriceList(v.getId());
			}
		});
		
		return v;
    }
    
    /**
     * <pre>
     * historyLoad
     * void
     * </pre>
     */
    public void BrandForLog(){
    	
    	//테스트 히스토리 데이터를 가져 온다.
    	brand_list.removeAllViews();
        for(int i = 0 ; i <  8 ; i++){
        	
        	brand_list.addView(brandAddView(i));
        }
    }
    
}